package com.lib.controller.agent;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lib.application.RentalAgentQRCodeService;
import com.lib.controller.AbstractScopeController;
import com.lib.model.enums.RentalAgentWxStatusEnum;
import com.lib.service.BaseWxService;
import com.lib.service.WxAgentService;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by duqingxiang on 17/5/18.
 */
@Controller
@RequestMapping("/agent/menu")
public class RentalAgentMenuController extends AbstractScopeController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    RentalAgentQRCodeService rentalAgentQRCodeService;

    @Autowired
    WxAgentService wxService;


    @RequestMapping("/myCode")
    public ModelAndView myCode(@RequestParam String code, HttpServletRequest request){
        String openId = this.getOpenId(request);

        String ticket = rentalAgentQRCodeService.getMyCode(openId);

        ModelAndView view = new ModelAndView();
        view.addObject("show", StringUtils.isBlank(ticket));
        view.addObject("ticket",ticket);
        view.setViewName("wxShow/agent/agent_mycode");
        return view;
    }

    @Override
    protected BaseWxService getWXService() {
        return this.wxService;
    }
}
